using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NCS.Module.CMS.Library;
using NCS.Module.CMS.Library.Definitions;
using NCS.Module.CMS.Library.Distributions;
using NCS.Module.CMS.Library.Zones;
using NCS.Library;
using NCS.Library.Utilities;
using NCS.Library.Components.Partner;

namespace NCS.Module.CMS.Web.News
{
    public partial class LeftBottomNews : CMSWebControl
    {
        public int zoneid;
        protected void Page_Load(object sender, EventArgs e)
        {
            int catid = ConvertUtility.ToInt32(Request.QueryString["catid"]);
            if (catid != 0)
            {
                Advertisement1.Param = "catid";
            }
            
            zoneid = ConvertUtility.ToInt32(Portal[Constants.CMS_Phongsu_Kysu + AppEnv.GetLanguage()]);
            ZoneInfo info = ZoneController.GetZone(zoneid);
            hplCaption.Text = info.Zone_Name;
            hplCaption.NavigateUrl = BuildUrlByZone(zoneid, info.Portal_TabControlID);
            hplMore.NavigateUrl = BuildUrlByZone(zoneid, info.Portal_TabControlID);
          
            DataTable left = DistributionController.GetDistributedContents(zoneid, 4,(int)CMSDistributionRank.Special);
            rptBottomNews.DataSource = left;
            rptBottomNews.ItemDataBound += new RepeaterItemEventHandler(rptBottomNews_ItemDataBound);
            rptBottomNews.DataBind();

        }

        protected void rptBottomNews_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemIndex < 0) return;
            DataRowView currow = (DataRowView)e.Item.DataItem;
            Image imgPic = (Image)e.Item.FindControl("imgPic");
            imgPic.ImageUrl = ConvertUtility.ToString(currow["Content_Avatar"]) != string.Empty ? MultimediaUtility.GetListAvatar(currow["Content_Avatar"].ToString()) : "";
            if (imgPic.ImageUrl == "") imgPic.Visible = false;

            HyperLink hplTitle = (HyperLink)e.Item.FindControl("hplTitle");

            string tooltip = MiscUtility.ToolTip(ConvertUtility.ToString(currow["Content_Headline"]), ConvertUtility.ToString(currow["Content_SubTitle"]), ConvertUtility.ToString(currow["Content_Avatar"]), ConvertUtility.ToString(currow["Content_Teaser"]), ConvertUtility.ToString(currow["Content_Alias"]), ConvertUtility.ToDateTime(currow["Distribution_CreateDate"]));
            hplTitle.Attributes.Add("onmouseover", "showtip('" + tooltip + "','322','#EBF3FB')");
            hplTitle.Attributes.Add("onmouseout", "hidetip()");

            hplTitle.NavigateUrl = BuildUrlByDistId((int)currow["Distribution_ID"], zoneid);
        }
    }
}